package com.errorfinding.rabbitmq.seven;

import com.errorfinding.rabbitmq.util.RabbitMqUtils;
import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

/**
 * 生产者
 * 主题交换机模式 topic
 */
public class EmitLogTopic {
    private static final String exchange_name = "topic_logs";

    public static void main(String[] args) throws IOException, TimeoutException {
        //获取信道
        Channel channel = RabbitMqUtils.getChannel();
        //创建交换机
        channel.exchangeDeclare(exchange_name,"topic");
        //发送消息
        Map<String,String> bindingKeyMap = new HashMap<>();
        bindingKeyMap.put("quick.orange.rabbit","被队列0102接收到");
        bindingKeyMap.put("lazy.orange.elephant","被队列0102接收到");

        bindingKeyMap.entrySet().forEach(item->{
            try {
                channel.basicPublish(exchange_name,item.getKey(),null,item.getValue().getBytes("utf-8"));
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
            System.out.println("生产者发送消息："+item.getValue());
        });
    }
}
